//
//  DataArrModel.swift
//  Pods
//
//  Created by eme on 2017/4/5.
//
//

import Foundation
import SwiftyJSON
import ModelProtocol

class DataArrModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kDataArrPdnameKey: String = "pdname"
    internal let kDataArrPdidKey: String = "pdid"
    internal let kDataArrPsfnameKey: String = "psfname"
    internal let kDataArrPdnumKey: String = "pdnum"
    internal let kDataArrImg1Key: String = "img1"
    internal let kDataArrPsvalueKey: String = "psvalue"
    internal let kDataArrSkuidKey: String = "skuid"
    internal let kDataArrPsfname2Key: String = "psfname2"
    internal let kDataArrOrderidKey: String = "orderid"
    internal let kDataArrPsvalue2Key: String = "psvalue2"
    internal let kDataArrPdtypeKey: String = "pdtype"
    internal let kDataArrShpriceKey: String = "shprice"
    internal let kDataArrDetailrnumberKey: String = "detailrnumber"
    
    
    // MARK: 属性
    var pdname: String
    var pdid: Int
    var psfname: String
    var pdnum: Int
    var img1: String
    var psvalue: String
    var skuid: Int
    var psfname2: String
    var orderid: String
    var psvalue2: String
    var pdtype: String
    var shprice: Double
    var detailrnumber: Int
    var standard:String{
        get{
            if psfname == ""
            {
                return ""
            }
            else if psfname2 == ""
            {
                if psvalue != ""{
                    return self.psfname + ":" + self.psvalue
                }else{
                    return self.psfname
                }
                
            }
            else
            {
                if self.psvalue != "" && psvalue2 != ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue == "" && psvalue2 != ""{
                    
                    return self.psfname + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue != "" && psvalue2 == ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2
                    
                }else{
                    return self.psfname + ";" + self.psfname2
                    
                }
            }
            
        }
        
    }
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        pdname = json[kDataArrPdnameKey].stringValue
        pdid = json[kDataArrPdidKey].intValue
        psfname = json[kDataArrPsfnameKey].stringValue
        pdnum = json[kDataArrPdnumKey].intValue
        img1 = json[kDataArrImg1Key].stringValue
        psvalue = json[kDataArrPsvalueKey].stringValue
        skuid = json[kDataArrSkuidKey].intValue
        psfname2 = json[kDataArrPsfname2Key].stringValue
        orderid = json[kDataArrOrderidKey].stringValue
        psvalue2 = json[kDataArrPsvalue2Key].stringValue
        pdtype = json[kDataArrPdtypeKey].stringValue
        shprice = json[kDataArrShpriceKey].doubleValue
        detailrnumber = json[kDataArrDetailrnumberKey].intValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(pdname as AnyObject, forKey: kDataArrPdnameKey)
    
        dictionary.updateValue(pdid as AnyObject,  forKey: kDataArrPdidKey)
    
        dictionary.updateValue(psfname as AnyObject, forKey: kDataArrPsfnameKey)
    
        dictionary.updateValue(pdnum as AnyObject, forKey: kDataArrPdnumKey)
    
        dictionary.updateValue(img1  as AnyObject, forKey: kDataArrImg1Key)
    
        dictionary.updateValue(psvalue  as AnyObject, forKey: kDataArrPsvalueKey)
    
        dictionary.updateValue(skuid  as AnyObject, forKey: kDataArrSkuidKey)
    
        dictionary.updateValue(psfname2  as AnyObject, forKey: kDataArrPsfname2Key)
    
        dictionary.updateValue(orderid  as AnyObject, forKey: kDataArrOrderidKey)
    
        dictionary.updateValue(psvalue2  as AnyObject, forKey: kDataArrPsvalue2Key)
    
        dictionary.updateValue(pdtype  as AnyObject, forKey: kDataArrPdtypeKey)
   
        dictionary.updateValue(shprice  as AnyObject, forKey: kDataArrShpriceKey)
    
        dictionary.updateValue(detailrnumber  as AnyObject, forKey: kDataArrDetailrnumberKey)
        
        
        return dictionary
    }
    
    
}
